package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

//向http返回响应

type sendMsgToHttpRspData struct {
	Code int         `json:"code" form:"code"`
	Msg  string      `json:"msg" form:"msg"`
	Data interface{} `json:"data" form:"data"`
}

func sendMsgToHttp(ctx *gin.Context, result interface{}, err error) {
	data := &sendMsgToHttpRspData{Code: http.StatusOK}
	if err != nil {
		data.Msg = err.Error()
		data.Code = http.StatusInternalServerError
	} else {
		data.Data = result
	}
	ctx.JSON(http.StatusOK, data)
}
